package com.chery.media.ui.music

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.chery.media.R
import com.chery.media.library.extend.toColorInt
import com.chery.media.network.model.MusicBean

class MusicAdapter: BaseQuickAdapter<Triple<Int, Int, String>, BaseViewHolder>(R.layout.item_music_type) {

    var selectIndex = 0

    override fun convert(holder: BaseViewHolder, item: Triple<Int, Int, String>) {
        holder.apply {
            setImageResource(R.id.typeIcon, if (selectIndex != layoutPosition) item.first else item.second)
            setText(R.id.typeName, item.third)
            setTextColor(R.id.typeName, if (selectIndex != layoutPosition) R.color.public_66FFFFFF.toColorInt() else R.color.public_FDCD19.toColorInt())
            setBackgroundResource(R.id.selectArea, if (selectIndex == layoutPosition) R.drawable.shape_set_selected_bg else R.color.transparent)
            setGone(R.id.selectLine, selectIndex != layoutPosition)
        }
    }

    fun setSelect(index: Int) {
        this.selectIndex = index
        notifyDataSetChanged()
    }

}

class MusicListAdapter: BaseQuickAdapter<MusicBean, BaseViewHolder>(R.layout.item_music) {

    override fun convert(holder: BaseViewHolder, item: MusicBean) {
        holder.apply {
            setText(R.id.sortText, "${layoutPosition + 1}")
            val name = if (item.title.isNullOrEmpty()) item.playPath?.substring(item.playPath!!.lastIndexOf("/") + 1, item.playPath!!.lastIndexOf(".")) ?: "" else item.title
            setText(R.id.musicNameText, name)
        }
    }

}